package cn.meibang.common.beauty.provider.dao;

import cn.apestar.core.database.BaseMapper;
import cn.meibang.common.beauty.provider.domain.BeautyConsultationOrderUserConsultantLatest;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface BeautyConsultationOrderUserConsultantLatestMapper extends BaseMapper {
    @Delete({
            "delete from beauty_consultation_order_user_consultant_latest",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Delete({
            "delete from beauty_consultation_order_user_consultant_latest",
            "where user_id = #{userId,jdbcType=BIGINT} and store_id = #{storeId,jdbcType=BIGINT} and consultant_id = #{consultantId,jdbcType=BIGINT}"
    })
    int delete(@Param("userId") Long userId, @Param("storeId") Long storeId, @Param("consultantId") Long consultantId);

    @Delete({
            "delete from beauty_consultation_order_user_consultant_latest",
            "where openid = #{openid,jdbcType=VARCHAR} and store_id = #{storeId,jdbcType=BIGINT} and consultant_id = #{consultantId,jdbcType=BIGINT}"
    })
    int deleteByOpenid(@Param("openid") String openid, @Param("storeId") Long storeId, @Param("consultantId") Long consultantId);

    @Insert({
            "insert into beauty_consultation_order_user_consultant_latest (id, tag, ",
            "user_id, openid, store_id, store_name, consultant_id, ",
            "consultant_name, consultant_img)",
            "values (#{id,jdbcType=BIGINT}, #{tag,jdbcType=VARCHAR}, ",
            "#{userId,jdbcType=BIGINT}, #{openid}, #{storeId,jdbcType=BIGINT}, #{storeName}, #{consultantId,jdbcType=BIGINT}, ",
            "#{consultantName,jdbcType=VARCHAR}, #{consultantImg,jdbcType=VARCHAR})"
    })
    int insert(BeautyConsultationOrderUserConsultantLatest record);

    @InsertProvider(type = BeautyConsultationOrderUserConsultantLatestSqlProvider.class, method = "insertSelective")
    int insertSelective(BeautyConsultationOrderUserConsultantLatest record);

    @Select({
            "select",
            "id, tag, user_id, openid, store_id, store_name, consultant_id, consultant_name, consultant_img",
            "from beauty_consultation_order_user_consultant_latest",
            "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "tag", property = "tag", jdbcType = JdbcType.VARCHAR),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.BIGINT),
            @Result(column = "openid", property = "openid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_id", property = "storeId", jdbcType = JdbcType.BIGINT),
            @Result(column = "store_name", property = "storeName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "consultant_id", property = "consultantId", jdbcType = JdbcType.BIGINT),
            @Result(column = "consultant_name", property = "consultantName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "consultant_img", property = "consultantImg", jdbcType = JdbcType.VARCHAR)
    })
    BeautyConsultationOrderUserConsultantLatest selectByPrimaryKey(Long id);


    @SelectProvider(type = BeautyConsultationOrderUserConsultantLatestSqlProvider.class, method = "selectPageByUserIdAndOpenidAndStoreId")
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "tag", property = "tag", jdbcType = JdbcType.VARCHAR),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.BIGINT),
            @Result(column = "openid", property = "openid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_id", property = "storeId", jdbcType = JdbcType.BIGINT),
            @Result(column = "store_name", property = "storeName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "consultant_id", property = "consultantId", jdbcType = JdbcType.BIGINT),
            @Result(column = "consultant_name", property = "consultantName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "consultant_img", property = "consultantImg", jdbcType = JdbcType.VARCHAR)
    })
    List<BeautyConsultationOrderUserConsultantLatest> selectPageByUserIdAndOpenidAndStoreId(@Param("userId") Long userId,
                                                                                            @Param("openid") String openid,
                                                                                            @Param("storeId") Long storeId,
                                                                                            @Param("offset") int offset,
                                                                                            @Param("size") int size);

    @UpdateProvider(type = BeautyConsultationOrderUserConsultantLatestSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(BeautyConsultationOrderUserConsultantLatest record);

    @Update({
            "update beauty_consultation_order_user_consultant_latest",
            "set tag = #{tag,jdbcType=VARCHAR},",
            "user_id = #{userId,jdbcType=BIGINT},",
            "openid = #{openid,jdbcType=VARCHAR},",
            "store_id = #{storeId,jdbcType=BIGINT},",
            "store_name = #{storeName,jdbcType=VARCHAR},",
            "consultant_id = #{consultantId,jdbcType=BIGINT},",
            "consultant_name = #{consultantName,jdbcType=VARCHAR},",
            "consultant_img = #{consultantImg,jdbcType=VARCHAR}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(BeautyConsultationOrderUserConsultantLatest record);
}